package com.test.daily.leetcode.y2022.m04.day0419.v0014;

/**
 * @author Tom on 2022/4/19
 */
public class Solution {
    public static void main(String[] args) {

    }
    public String longestCommonPrefix(String[] strs){
        int N = strs.length;
        StringBuffer strBuffer = new StringBuffer();
        int minSubStrLength = Integer.MAX_VALUE;
        for (int i = 0; i < N; i++) {
            minSubStrLength = Math.min(strs[i].length(), minSubStrLength);
        }
        for (int i = 0; i < minSubStrLength; i++) {
            for (int j = 0; j < N; j++) {
                if(j < N -1 && strs[j].charAt(i) != strs[j+1].charAt(i)){
                    return strBuffer.toString();
                }
            }
            strBuffer.append(strs[0].charAt(i));
        }
        return strBuffer.toString();
    }
}
